#include "HpBar.h"

bool HpBar::init(const char* background, const char* fillName) {
    this->initWithSpriteFrameName(background);
    ProgressTimer* fill = ProgressTimer::create(Sprite::createWithSpriteFrameName(fillName));
    this->setFill(fill);
    this->addChild(fill);
    fill->setType(ProgressTimer::Type::BAR);
    fill->setMidpoint(Vec2(0, 0.5));
    fill->setBarChangeRate(Vec2(1.0, 0));
    fill->setPosition(this->getContentSize() / 2);
    fill->setPercentage(100);
    return true;
}

HpBar* HpBar::create(const char* background, const char* fillName) {
    auto hb = new HpBar();
    if(hb && hb->init(background, fillName)) {
        hb->autorelease();
        return hb;
    }
    else {
        delete hb;
        hb = nullptr;
        return nullptr;
    }
}